package com.ls.dao.role;

import com.ls.dao.BaseDao;
import com.ls.pojo.Role;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author 李朔
 * @version 1.0
 */
public class RoleDaoImpl implements RoleDao{

    public List<Role> getRoleList(Connection connection) throws SQLException {
            PreparedStatement preparedStatement=null;
            ArrayList<Role> roleArrayList=new ArrayList<Role>();
            //获取角色列表
            if(connection!=null){
                String sql="select * from smbms_role";
                Object[] params={};
                ResultSet resultSet = BaseDao.executeQuery(connection, sql, params, preparedStatement, null);

                while(resultSet.next()){
                    Role _role=new Role();
                    int id = resultSet.getInt("id");
                    String roleCode = resultSet.getString("roleCode");
                    String roleName = resultSet.getString("roleName");
                    _role.setId(id);
                    _role.setRoleCode(roleCode);
                    _role.setRoleName(roleName);
                    roleArrayList.add(_role);
                }
                BaseDao.closeResource(null,preparedStatement,resultSet);
            }
            return roleArrayList;
        }

}

